//10.6 - Encryption Program - Dirk Henkemans //Prima Publishing //A text data encryption program #include #include using namespace std; class Encryption { fstream file1;//source file fstream file2;//destination file public: Encryption::Encryption(char* filename1, char* filename2) { file1.open(filename1, ios::in | ios::out | ios::binary); file2.open(filename2, ios::out|ios::binary); } //encrypts the file void Encrypt(void) { char currentByte; bool currentBit; int index = 0; //sets the pointers to the beginning of the file file1.seekg (0, ios::beg); file2.seekp (0, ios::beg); //reads the first value file1.read(¤tByte, 1); while(file1.good()) { //loop for four bits for(int c = 0; c < 4; c++) { //finds out if the first bit is a one currentBit = (int)((unsigned char)currentByte / 128); //shifts the byte over currentByte <<= 1; //if the first bit was a one then we add it to the end if(currentBit) { currentByte += 1; } } //writes the character file2.write(¤tByte, 1); //increments the pointer file1.seekg (++index); file2.seekp (index); //reads the next value file1.read(¤tByte, 1); } } //closes both of the files void close(void) { file1.close(); file2.close(); } }; int main( void ) { cout<< "Welcome to the S.A.S encryption program."; Encryption delta("dragons.txt", "output1.txt"); delta.Encrypt(); delta.close(); Encryption gamma("output1.txt", "output2.txt"); gamma.Encrypt(); delta.close(); return 0; }